﻿using System;
using System.IO.IsolatedStorage;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Caliburn.Micro;
using RemoteControl.Localization;

namespace RemoteControl.ViewModels
{
    public class ConfigViewModel : Screen
    {
        private readonly INavigationService navigationService;
        private string ipAddress;

        public string IPAddress
        {
            get { return ipAddress; }
            set
            {
                ipAddress = value;
                NotifyOfPropertyChange(() => IPAddress);
            }
        }

        public ConfigViewModel(INavigationService navigationService)
        {
            this.navigationService = navigationService;
        }

        protected override void OnViewLoaded(object view)
        {
            base.OnViewLoaded(view);
            IPAddress = IPEndPointStorage.IPAddress;
        }
        
        public void OnSave()
        {
            if (string.IsNullOrEmpty(IPAddress))
            {
                MessageBox.Show(AppResources.Please_set_the_IP_of_the_receiver);
                return;
            }
            IPEndPointStorage.IPAddress = IPAddress;
            navigationService.GoBack();
        }
    }
}
